package cn.com.anypay.manager.payment.dto;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * 支付结果数据传输对象
 *
 * 包含支付操作的返回结果
 *
 * @author AnyPay Team
 * @version 1.0
 * @since 2025-07-05
 */
public class PaymentResultDTO {

    /**
     * 操作是否成功
     */
    private boolean success;

    /**
     * 错误代码
     */
    private String errorCode;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 商户订单号
     */
    private String merchantOrderId;

    /**
     * 渠道订单号
     */
    private String channelOrderId;

    /**
     * 支付状态
     */
    private PaymentStatusDTO status;

    /**
     * 支付金额
     */
    private BigDecimal amount;

    /**
     * 支付URL（用于跳转支付页面）
     */
    private String payUrl;

    /**
     * 支付二维码内容
     */
    private String qrCode;

    /**
     * 支付HTML代码（用于内嵌支付）
     */
    private String htmlCode;

    /**
     * 支付时间
     */
    private Date payTime;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 渠道响应的原始数据
     */
    private String rawData;

    /**
     * 扩展数据
     */
    private Map<String, Object> extData;

    public PaymentResultDTO() {
        this.createTime = new Date();
    }

    public PaymentResultDTO(boolean success) {
        this();
        this.success = success;
    }

    public PaymentResultDTO(boolean success, String errorCode, String errorMessage) {
        this();
        this.success = success;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    /**
     * 创建成功结果
     */
    public static PaymentResultDTO success() {
        return new PaymentResultDTO(true);
    }

    /**
     * 创建成功结果
     */
    public static PaymentResultDTO success(String merchantOrderId, String channelOrderId) {
        PaymentResultDTO result = new PaymentResultDTO(true);
        result.setMerchantOrderId(merchantOrderId);
        result.setChannelOrderId(channelOrderId);
        return result;
    }

    /**
     * 创建失败结果
     */
    public static PaymentResultDTO failure(String errorCode, String errorMessage) {
        return new PaymentResultDTO(false, errorCode, errorMessage);
    }

    // Getters and Setters
    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getMerchantOrderId() {
        return merchantOrderId;
    }

    public void setMerchantOrderId(String merchantOrderId) {
        this.merchantOrderId = merchantOrderId;
    }

    public String getChannelOrderId() {
        return channelOrderId;
    }

    public void setChannelOrderId(String channelOrderId) {
        this.channelOrderId = channelOrderId;
    }

    public PaymentStatusDTO getStatus() {
        return status;
    }

    public void setStatus(PaymentStatusDTO status) {
        this.status = status;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public String getPayUrl() {
        return payUrl;
    }

    public void setPayUrl(String payUrl) {
        this.payUrl = payUrl;
    }

    public String getQrCode() {
        return qrCode;
    }

    public void setQrCode(String qrCode) {
        this.qrCode = qrCode;
    }

    public String getHtmlCode() {
        return htmlCode;
    }

    public void setHtmlCode(String htmlCode) {
        this.htmlCode = htmlCode;
    }

    public Date getPayTime() {
        return payTime;
    }

    public void setPayTime(Date payTime) {
        this.payTime = payTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getRawData() {
        return rawData;
    }

    public void setRawData(String rawData) {
        this.rawData = rawData;
    }

    public Map<String, Object> getExtData() {
        return extData;
    }

    public void setExtData(Map<String, Object> extData) {
        this.extData = extData;
    }

    @Override
    public String toString() {
        return "PaymentResult{" +
                "success=" + success +
                ", errorCode='" + errorCode + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                ", merchantOrderId='" + merchantOrderId + '\'' +
                ", channelOrderId='" + channelOrderId + '\'' +
                ", status=" + status +
                ", amount=" + amount +
                ", payUrl='" + payUrl + '\'' +
                ", qrCode='" + qrCode + '\'' +
                ", htmlCode='" + htmlCode + '\'' +
                ", payTime=" + payTime +
                ", createTime=" + createTime +
                ", rawData='" + rawData + '\'' +
                ", extData=" + extData +
                '}';
    }
}